<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<div class="line-big">
	<div class="xl2"></div>
	<div class="xl8">
		<div class="panel border-back" id="write_special_commission_div">
			<div class="panel-body text-center">
				<h1>
					<strong>添加特殊佣金</strong>
				</h1>
			</div>
			<div class="panel-foot bg-white border-back">
				<div class="line-big">
					<div class="xl4">
						<div class="form-group">
							<div class="label">
								<label for="buyerId">*买家编号(25位)</label>
							</div>
							<div class="field">
								<input type="text" class="input" value="${param.buyerId }" id="buyerId" data-regex="^\S.{0,23}\S$" />
							</div>
						</div>
					</div>
					<div class="xl4">
						<div class="form-group">
							<div class="label">
								<label for="goodsId">*商品编号(25位)</label>
							</div>
							<div class="field">
								<input type="text" class="input" value="${param.goodsId }" id="goodsId" data-regex="^\S.{0,23}\S$" />
							</div>
						</div>
					</div>
					<div class="xl4">
						<div class="form-group">
							<div class="label">
								<label for="goodsCommission">*商品特殊佣金(最多两位小数)</label>
							</div>
							<div class="field">
								<input type="text" class="input" id="goodsCommission" value="" data-regex="^(0|[1-9][0-9]{0,9})(.[0-9]{1,2})?$" />
							</div>
						</div>
					</div>
				</div>

			</div>
			<div class="panel-foot bg-white">
				<div class="line-big margin-top margin-bottom">
					<div class="xl4"></div>
					<div class="xl4 text-center">
						<button class="button border-blue" id="submit_special_commission_button">提交佣金信息</button>
					</div>
					<div class="xl4"></div>
				</div>
			</div>
		</div>
		<div id="add_success_div" class="G-MarginTop100" style="display: none;">
			<div class="line-big">
				<div class="xl3"></div>
				<div class="xl6 text-center">
					<h1 class="text-center">
						<span class="icon-check-circle text-yellow"></span> 提交佣金信息成功了。
					</h1>
					<br />
					<p>
						<button class="button bg-blue" id="go_on_add_special_commission">
							<span class="icon-plus-circle"></span> 继续添加特殊佣金
						</button>
						<button class="button bg-green margin-top click_go_to_nav_button" data-trigger-id="#sub_see_on_sale_goods">
							<span class="icon-eye"></span> 去查看销售中的商品
						</button>
						<button class="button bg-green margin-top click_go_to_nav_button" data-trigger-id="#sub_see_used_buyer">
							<span class="icon-eye"></span> 去查看使用中的买家
						</button>
					</p>
				</div>
				<div class="xl3"></div>
			</div>
		</div>
	</div>
	<div class="xl2"></div>
</div>
<div style="display: none" id="time_temp_div"></div>

<script type="text/javascript">
	$(function()
	{

		$("#submit_special_commission_button").click(function()
		{
			var buyerId = $("#buyerId").val();
			var goodsId = $("#goodsId").val();
			var goodsCommission = $("#goodsCommission").val();

			if (goodsId.length <= 0 || buyerId.length <= 0 || goodsCommission.length <= 0)
			{
				alert("标有*的输入项都是必填项.")
				return false;
			}

			var tips = "";
			var tips_number = 1;
			$("#buyerId,#goodsId,#goodsCommission").each(function(i, dom)
			{
				var n = $(dom);
				if (new RegExp(n.attr("data-regex")).test(n.val()) == false)
				{
					tips += tips_number++ + " . \"" + n.val() + "\" 不满足输入要求;\n";
				}
			});

			if (tips.length > 0)
			{
				alert(tips + "\n请检查一下重新输入.");
				return false;
			}

			var submit_special_commission_button_html = $("#submit_special_commission_button").html();
			$.ajax(
			{
				url : "admin/m_add_special_commission_do",
				type : "POST",
				dataType : "json",
				beforeSend : function(XMLHttpRequest)
				{
					$("#submit_special_commission_button").attr("disabled", "disabled");
					$("#submit_special_commission_button").html("正在提交佣金信息中...");
				},
				data :
				{
					'goodsCommission.buyerId' : buyerId,
					'goodsCommission.goodsId' : goodsId,
					'goodsCommission.goodsCommission' : goodsCommission
				},
				success : function(json, textStatus)
				{
					if (json.success == true)
					{
						$("#write_special_commission_div").slideUp();
						$("#add_success_div").slideDown(function()
						{
							$(".admin").animate(
							{
								scrollTop : 0
							}, 0);
						});
					}
					else
					{
						alert(json.info);
					}
				},
				error : function(XMLHttpRequest, textStatus, errorThrown)
				{
					alert("提交失败，请仔细检查您的输入是否满足要求。");
				},
				complete : function(XMLHttpRequest, textStatus)
				{
					$("#submit_special_commission_button").removeAttr("disabled");
					$("#submit_special_commission_button").html(submit_special_commission_button_html);
				}
			});
		});

		$("#go_on_add_special_commission").click(function()
		{
			$("#add_success_div").slideUp();
			$("#write_special_commission_div").slideDown(function()
			{
				if ("${param.buyerId }".length <= 0)
				{
					$("#buyerId").val("");
				}
				if ("${param.goodsId }".length <= 0)
				{
					$("#goodsId").val("");
				}
				$("#goodsCommission").val("");
			});
		});

	});
</script>